var options={
	page_id:39,
	grid_id:"gridList",
	pager_id:"pager",
	sqlname:"grid_sys_pub_news"
};
//document ready
$(function(){
	grid1=new uniontrip.datagrid.searchEdit(options);
	
	$('#addButton').bind('click', addRow);//新增行绑定事件
	$('#editButton').bind('click',onUpdate);//编辑按钮绑定事件
	$('#removeButton').bind('click',function(){gridConfirm(grid1.grid,"是否确认删除？",deleteSubmit);});//删除行绑定事件
	$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
	$('#btn1').bind('click',onView);//编辑按钮绑定事件
	$('#btn2').bind('click',publish);
    //初始化搜索框
    initsearch();
    initsessioninfo();
});

/**
 * 新增一行
 */
function addRow(){
	parent.addTab("新增资讯","/view/sys/pub_news/form.html");
}

function publish(){
	var selectRows=grid1.grid.datagrid('getSelections');
	if(selectRows.length>0){
		$._post("/authenticated/mnews/publish",JSON.stringify({id:selectRows[0].id}),function(result){
			if(result.success){
				$.messager.alert("提示", "发布成功！");
				grid1.load();
			}
		});
	}else{
		$.messager.alert("提示", "请选择一条数据！");
	}
	
}
function onUpdate(){
	var selectRows=grid1.grid.datagrid('getSelections');
	if(selectRows.length>0){
		parent.addTab("编辑["+selectRows[0].id+"]","/view/sys/pub_news/form.html?id="+selectRows[0].id);
	}else{
		$.messager.alert("提示", "请选择一条数据！");
	}
}
function onView(){
	var selectRows=grid1.grid.datagrid('getSelections');
	if(selectRows.length>0){
		window.open("/authenticated/mnews/view?id="+selectRows[0].id);
	}else{
		$.messager.alert("提示", "请选择一条数据！");
	}
}
/**
 * 删除提交
 * @param selectRow
 */
function deleteSubmit(selectRow){
	$._post("/authenticated/ajax/update/grid_sys_pub_news-delete",JSON.stringify({ids:[selectRow.id]}),function(result){
		if(result.success){
			$.messager.alert("提示", "删除成功！");
			grid1.load();
		}
	});
}
/**
 * 初始化搜索条件
 */
function initsearch(){
	/*$('#search-product_class_id').combotree({
		icons: [{
			iconCls:'icon-clear',
			handler:function(){
				$('#search-product_class_id').combotree('clear');
			}
		}],
	    data:grid1.combotreeDatas.product_class_id
	});
	//初始化combobox例子
	$('#search-status').combobox({
		panelHeight:'auto',
		editable:false,
		valueField:'code_value',
		textField:'code_name',
		icons: [{
			iconCls:'icon-clear',
			handler:function(){
				$('#search-status').combobox('clear');
			}
		}],
	    data:grid1.comboboxDatas.status
	});*/
}